package com.ymttest.database.sqlwapper.fastturnover;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.fastturnover.TurnoverApply;

public class TurnoverApplyWrapper {
	
	SqlManager manager;

	public TurnoverApplyWrapper() {
		manager = new SqlManager("fastturnover");
	}

	@SuppressWarnings("unchecked")
	public TurnoverApply selectByPrimaryKey(String id) {

		TurnoverApply turnoverApply = new TurnoverApply();
		List<TurnoverApply> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			turnoverApply = result.get(0);
		}
		
		return turnoverApply;
	}
	
	@SuppressWarnings("unchecked")
	public List<TurnoverApply> selectBySellerId(Long sellerId) {

		List<TurnoverApply> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.selectBySellerId",
						sellerId);
		manager.commit();
		
		return result;
	}
	
	public int insertSelective(TurnoverApply turnoverApply) {

		int result = manager
				.insert(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.insertSelective",
						turnoverApply);
		manager.commit();
		
		return result;
	}
	
	public int updateToFinishByApplyNo(String applyNo) {

		int result = manager
				.update(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.updateToFinishByApplyNo",
						applyNo);
		
		manager.commit();
		
		return result;
	}
	
	public int updateToInitByApplyNo(String applyNo) {

		int result = manager
				.update(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.updateToInitByApplyNo",
						applyNo);
		
		manager.commit();
		
		return result;
	}
	
	public int deleteByApplyNoAndSellerId(String applyNo, Long sellerId) {

		HashMap<String, Object> map = new HashMap<>();
		
		map.put("applyNo", applyNo);
		map.put("sellerId", sellerId);
		
		int result = manager
				.delete(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.deleteByApplyNoAndSellerId",
						map);
		manager.commit();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TurnoverApply selectBySellerIdAndPayStatus(Long sellerId, Integer payStatus) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payStatus", payStatus);
		map.put("sellerId", sellerId);
		
		TurnoverApply turnoverApply = new TurnoverApply();
		List<TurnoverApply> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyMapper.selectBySellerIdAndPayStatus",
						map);
		manager.commit();
		
		if (result.size() > 0) {
			turnoverApply = result.get(0);
		}
		
		return turnoverApply;
	}
	
	public static void main(String[] args) {
		
		TurnoverApplyWrapper test = new TurnoverApplyWrapper();
		
		System.out.println(test.updateToFinishByApplyNo("FKT2020040300000019"));
	}
}
